package org.itcast.annotationandresttemplate.swaggerTest.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.itcast.annotationandresttemplate.swaggerTest.entity.PageResult;
import org.itcast.annotationandresttemplate.swaggerTest.entity.SwaggerDTO;
import org.itcast.annotationandresttemplate.swaggerTest.mapper.SwaggerMapper;
import org.itcast.annotationandresttemplate.swaggerTest.service.SwaggerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SwaggerServiceImpl implements SwaggerService {
    @Autowired
    private SwaggerMapper swaggerMapper;
    @Override
    public int save(SwaggerDTO swaggerDTO) {

        return swaggerMapper.save(swaggerDTO);
    }

    @Override
    public List<SwaggerDTO> find(SwaggerDTO swaggerDTO) {
        return swaggerMapper.find(swaggerDTO);
    }

    @Override
    public PageResult findByPage(SwaggerDTO swaggerDTO) {
        PageHelper.startPage(swaggerDTO.getPageNum(),swaggerDTO.getPageSize());
        Page<SwaggerDTO> dtos = swaggerMapper.findByPage(swaggerDTO);
        long total = dtos.getTotal();
        List<SwaggerDTO> result = dtos.getResult();
        return new PageResult(total,result);
    }
}
